$(function(){
	//获取短信验证码 pointer-events: none; check-phone
	$("#getVerifyCode,#resendSpan").click(function(){
		var telphone = $("#telphone").val();
		var email = $.trim($("#email").val());
		if(isNull(email)){
            swal("警告","邮箱名不能为空","warning");
            return;
        }
        var emailReg = new RegExp(LTS.ReExp.email);
        if(!emailReg.test(email)){
            swal("警告","邮箱格式不正确","warning");
            return;
        } 
		if(isNull($.trim(telphone))){
			swal("警告","手机号不能为空","warning");
            return;
		}
		var telReg = new RegExp(LTS.ReExp.phone);
		if(!telReg.test(telphone)){
            swal("警告","手机格式不正确","warning");
            return;
        }
		var url = getRoot() + "/register/sendRegisterSms";
		var paramsObj = {};
		paramsObj['telphone'] = telphone;
		paramsObj['email'] = email;
		$.post(url,paramsObj,function(json){
			if (json && json.success) {
				$("#getVerifyCode").removeClass().addClass("disabledget");
				timeCountdown(60);
				$("#timeSpan").show();
            } else {
                if (json) {
                    swal("注册失败",json['message'], 'error');
                    $("#getVerifyCode").removeClass().addClass("check-phone");
                }
            }
		});
	});
    $(document).on("click", "#confirm-register", function () {
        var email = $.trim($("#email").val());
        var password = $("#password").val();
        if(isNull(email)){
            swal("警告","邮箱名不能为空","warning");
            return;
        }
        var emailReg = new RegExp(LTS.ReExp.email);
        if(!emailReg.test(email)){
            swal("警告","邮箱格式不正确","warning");
            return;
        }

        if(isNull(password)){
            swal("警告","密码不能为空","warning");
            return;
        }
        password = $.trim(password);
        var length = password.length;
        if(length < 6 || length > 10){
            swal("警告","密码长度应该在6到10之间，包括6和10","warning");
            return;
        }
        var params = {};
        params['email'] = email;
        params['password'] = password;
        var telphone = $("#telphone").val();
        var message_valid = $("#message_valid").val();
        if(isNull($.trim(telphone))){
			swal("警告","手机号不能为空","warning");
            return false;
		}
        message_valid = $.trim(message_valid);
        if(isNull(message_valid)){
        	swal("警告","验证码不能为空","warning");
            return false;
        }
        
        params['telphone'] = $.trim(telphone);
        params['messageValid'] = message_valid;
        params['project'] = $("#project option:selected").val();
        var url = getRoot() + "/register/newRegisterUser";
        $.postHttp(params,url,function(json){
            if (json && json.success) {
            	swal("注册成功",json['message'], 'success');
            } else {
                if (json) {
                    swal("注册失败",json['message'], 'error');
                }
            }
        });
    });

    function timeCountdown(countdown){
    	var count = countdown;
    	if(count == 0){ 
            $("#timeSpan").hide();
            $("#getVerifyCode").hide();
            $("#resendSpan").show();
            $("#getVerifyCode").removeClass().addClass("check-phone");
        	$("#resendSpan").removeClass().addClass("ressend");
            return;
        }else{ 
        	$("#getVerifyCode").removeClass().addClass("disabledget");
        	$("#resendSpan").removeClass().addClass("disabledget");
        	$("#time").html( count-1 +" s后重新获取"); 
            --count;
            console.log(count);
        }
    	setTimeout(function(){timeCountdown(count)},1000);
    }
    
});